<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>项目详情</title>
    <meta name="keywords" content="项目详">
    <meta name="description" content="项目详">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="<?= base_url('assets/css/bootstrap.min.css?v=3.3.6') ?>" rel="stylesheet">
    <link href="<?= base_url('assets/css/font-awesome.css?v=4.4.0') ?>" rel="stylesheet">
    <link href="<?= base_url('assets/css/animate.css') ?>" rel="stylesheet">
    <link href="<?= base_url('assets/css/style.css?v=4.1.0') ?>" rel="stylesheet">

</head>

<body class="gray-bg">
    <div class="row">
        <div class="col-sm-9">
            <div class="wrapper wrapper-content animated fadeInUp">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="m-b-md">


                                    <?php if($project_user_relation['role'] != AppConstants::PROJECT_ROLE_INTERPRETER) :?>

                                            <a href="javascript:open_project_dialog(<?=$project["id"] ?>)" class="btn btn-white btn-xs pull-right">编辑项目</a>
                                        &nbsp;&nbsp;
                                            <a href="javascript:open_key(<?=$project["id"] ?>)" class="btn btn-white btn-xs pull-right">KEY管理</a>
                                    <?php endif; ?>

                                    <a href="javascript:open_interpreter(<?=$project['id'] ?>)" class="btn btn-white btn-xs pull-right"><i class="fa fa-folder"></i>翻译录入</a>
                                    &nbsp;&nbsp;


                                    <h2><?= $project['name'] ?></h2>
                                </div>

                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-5">
                                <dl class="dl-horizontal">

                                    <dt>项目创建者：</dt>
                                    <dd><?= $owner['username']?></dd>
                                </dl>
                            </div>
                            <div class="col-sm-7" id="cluster_info">
                                <dl class="dl-horizontal">

                                    <dt>创建于：</dt>
                                    <dd>
                                        <?= TimeUtil::showtime($project["createtime"] , TimeUtil::TIME_ZONE_GMT8) ?>

                                    </dd>


                                    <dt>最后更新：</dt>
                                    <dd>
                                        <?= TimeUtil::showtime($project["updatetime"] , TimeUtil::TIME_ZONE_GMT8) ?>
                                    </dd>

                                </dl>
                            </div>
                        </div>

                        <div class="row m-t-sm">
                            <div class="col-sm-12">
                                <div class="panel blank-panel">
                                    <div class="panel-heading">
                                        <div class="panel-options">
                                            <ul class="nav nav-tabs">

                                                <li class="active" ><a href="project_detail.html#tab-1" data-toggle="tab">项目语言</a>
                                                </li>


                                                <li ><a href="project_detail.html#tab-2" data-toggle="tab">团队成员</a>
                                                </li>


                                                <li ><a href="project_detail.html#tab-3" data-toggle="tab">导出模板</a>
                                                </li>


                                                <li class=""><a href="project_detail.html#tab-4" data-toggle="tab">版本更新</a>
                                                </li>
                                            </ul>
                                        </div>
                                    </div>

                                    <div class="panel-body">

                                        <div class="tab-content">

                                            <div class="tab-pane active" id="tab-1">

                                                <?php if ($project_user_relation['role'] != AppConstants::PROJECT_ROLE_INTERPRETER) :?>
                                                   <a href="javascript:void(0)" class="btn btn-primary btn-xs" id="btn_add_lang">添加语言</a>
                                                <?php endif;?>

                                                <table class="table table-striped">

                                                    <thead>
                                                    <tr>
                                                        <th>语言名称</th>
                                                        <th>简写</th>
                                                        <th>添加时间</th>
                                                        <th>操作</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody id="tb_lang">




                                                    </tbody>
                                                </table>


                                            </div>




                                            <div class="tab-pane" id="tab-2">

                                                <?php if ($project_user_relation['role'] != AppConstants::PROJECT_ROLE_INTERPRETER) :?>
                                                   <a href="javascript:openProjectUserDialog('add', '')" class="btn btn-primary btn-xs">添加成员</a>
                                                <?php endif;?>

                                                <table class="table table-striped">

                                                    <thead>
                                                    <tr>
                                                        <th>成员</th>
                                                        <th>角色</th>
                                                        <th>添加时间</th>
                                                        <th>操作</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody id="tb_user">


                                                    </tbody>
                                                </table>


                                            </div>



                                            <div class="tab-pane" id="tab-3">

                                                <?php if ($project_user_relation['role'] != AppConstants::PROJECT_ROLE_INTERPRETER) :?>
                                                    <a href="javascript:void(0)" class="btn btn-primary btn-xs" id="btn_add_template">添加模板</a>


                                                <?php endif;?>

                                                <table class="table table-striped">

                                                    <thead>
                                                    <tr>
                                                        <th>模板名称</th>
                                                        <th>模板说明</th>
                                                        <th>添加时间</th>
                                                        <th>操作</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody id="tb_template">


                                                    </tbody>
                                                </table>


                                            </div>









                                            <div class="tab-pane" id="tab-4">

                                             
                                            </div>
                                        </div>

                                    </div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-3">
            <div class="wrapper wrapper-content project-manager">
                <h4>项目描述</h4>
              
                <p class="small">
                    <br><?= $project['remark']?>
                </p>

<!--                <div class="m-t-md">-->
<!--                    <a href="project_detail.html#" class="btn btn-xs btn-primary">添加KEY</a>-->
<!---->
<!--                </div>-->
            </div>
        </div>
    </div>




    <div class="modal inmodal fade" id="projectModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <form class="m-t" role="form" id="project_edit_form" action="index.html">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                        </button>
                        <h4 class="modal-title">编辑项目</h4>
                    </div>

                    <div class="modal-body">

                        <input type="hidden" name="pid" id="pid" value="">

                        <div class="form-group"><label>项目名称</label>
                            <input type="text" name="pname" id="pname" placeholder="请输入语言名称" class="form-control">
                        </div>



                        <div class="form-group"><label>项目描</label>
                            <textarea  name="remark" id="remark" class="form-control" ></textarea>
                        </div>


                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary" id="btn_dlg_lang_submit">保存</button>
                    </div>

                </form>
            </div>
        </div>
    </div>



    <div class="modal inmodal fade" id="userModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <form class="m-t" role="form" id="user_form" action="index.html">
                    <input type="hidden" class="form-control" id="user_op">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                        </button>
                        <h4 class="modal-title">添加团队成员</h4>
                    </div>

                    <div class="modal-body">

                        <input type="hidden" name="id" id="id" value="0">

                        <div class="form-group" id="dv_search_user"><label>用户</label>
                                <div class="input-group">
                                    <input type="text" class="form-control" id="search_user">
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                    <!-- /btn-group -->
                                </div>

                         </div>


                        <div class="form-group" id ="dv_edit_search_user"><label>用户</label>

                                <input type="text" class="form-control" id="edit_search_user" disabled >

                        </div>



                        <div class="form-group"><label>角色</label>
                            <select name="project_role" id="project_role" aria-controls="DataTables_Table_0" class="form-control input-sm" >
                                <option value="<?= AppConstants::PROJECT_ROLE_ADMIN?>">管理员</option>
                                <option value="<?= AppConstants::PROJECT_ROLE_INTERPRETER?>">翻译员</option>
                            </select>
                        </div>


                        <div class="form-group" id="lang_check_panel"><label>语言权限</label>


                            <table class="table table-striped">
                                <thead>
                                <tr>
                                    <th>选择</th>
                                    <th>语言</th>
                                    <th>简写</th>
                                    <th>读写权限</th>
                                </tr>
                                </thead>
                                <tbody id="tb_lang_choice">


                              </tbody>
                           </table>




                        </div>




                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" id="btn_add_user">保存</button>
                    </div>

                </form>
            </div>
        </div>
    </div>







    <div class="modal inmodal fade" id="langModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <form class="m-t" role="form" id="lang_form" action="index.html">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                        </button>
                        <h4 class="modal-title">语言</h4>
                    </div>

                    <div class="modal-body">

                        <input type="hidden" name="dlang_id" id="dlang_id" value="">


                        <div class="form-group"><label>语言名称</label>
                            <input type="text" name="lname" id="lname" placeholder="请输入语言名称" class="form-control">
                        </div>

                        <div class="form-group"><label>语言简写</label>
                            <input type="text" name="shorthand" id="shorthand" placeholder="请输入语言简写" class="form-control">
                        </div>


                        <div class="form-group"><label>备注说明</label>
                            <textarea  name="remark" id="remark" class="form-control" ></textarea>
                        </div>


                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary" id="btn_dlg_lang_submit">保存</button>
                    </div>

                </form>
            </div>
        </div>
    </div>




    <div class="modal inmodal fade" id="templateModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <form class="m-t" role="form" id="template_form" action="index.html">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                        </button>
                        <h4 class="modal-title">模板</h4>
                    </div>

                    <div class="modal-body">

                        <input type="hidden" name="tpl_id" id="tpl_id" value="">


                        <div class="form-group"><label>模板名称</label>
                            <input type="text" name="tplname" id="tplname" placeholder="请输入模板名称" class="form-control">



                        </div>



                        <div class="form-group"><label>模板目录规则</label>

                            <table class="table table-striped">
                                <thead>
                                <tr>
                                    <th>语言</th>
                                    <th>简写</th>
                                    <th>对应目录</th>
                                </tr>
                                </thead>

                                <tbody id="tb_tpl_folder">


                                </tbody>

                            </table>



                        </div>


                        <div class="form-group"><label>模板名称规则</label>
                            <input type="text" name="tplfilename" id="tplfilename" placeholder="请输入模板名称规则" class="form-control">
                            <span class="help-block m-b-none"><i class="fa fa-info-circle"></i>"#s" 为各个语言名称占位符,例如配置"#s_string.xml" 中文翻译导出的目录名为 "zh_string.xml"</span>

                        </div>


                        <div class="form-group"><label>模板描述</label>
                            <textarea  name="tplremark" id="tplremark" class="form-control" ></textarea>
                        </div>


                        <div class="alert alert-warning alert-dismissable" style="display: none" id="temp_desc">
                            <button aria-hidden="true"  class="close" type="button" onclick="tempte_desc(false)">×</button>
                                    例子-数据: <br/>
                                    KEY  &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;内容 <br/>
                                    APPNAME  &nbsp;&nbsp; --  小觅<br/>
                                    LOGIN    &nbsp;&nbsp;  --  登录<br/>
                                    <hr/>
                                    {datas}
                                    <br/>
                                    &nbsp;&nbsp;lang['{key}'] = '{value}';
                                    <br/>
                                    {/datas}
                                    <hr/>
                                    输出结果:
                                    <br/>
                                    lang['APPNAME'] = "小觅";
                                    <br/>
                                    lang['LOGIN']= "登录";
                                    <hr/>
                                    说明: 循环部分需要用 {data} 包起来, {key} 为KEY , {value} 为KE对应的值
                        </div>


                        <div class="form-group"><label><a href="javascript:tempte_desc(true)">模板内容(点击查看列子)</a></label>
                            <textarea  name="template" id="template" class="form-control" ></textarea>

                        </div>


                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary" id="btn_dlg_lang_submit">保存</button>
                    </div>

                </form>
            </div>
        </div>
    </div>



    <?php include "include/admin_foot_script.php" ?>
    <!-- Data Tables -->
    <script src="<?= base_url('assets/js/plugins/dataTables/jquery.dataTables.js') ?>"></script>
    <script src="<?= base_url('assets/js/plugins/dataTables/dataTables.bootstrap.js') ?>"></script>
    <!-- 自定义js -->
    <script src="<?= base_url('assets/js/content.js?v=1.0.0') ?>"></script>
    <script src="<?= base_url('assets/js/plugins/suggest/bootstrap-suggest.min.js') ?>"></script>






    <script>


        function tempte_desc(show) {

            if (show) {
                $("#temp_desc").show();
            } else {
                $("#temp_desc").hide();
            }


        }

        function open_interpreter(pid) {
            //window.location.href = "<?= base_url('admin/content/data?pid=') ?>" + pid;
            window.open("<?= base_url('admin/content/data?pid=') ?>" + pid, '翻译', 'fullscreen=1, channelmode= 1,location=0, menubar=no');
        }

        var pid = <?= $project['id']?>;

        var testdataBsSuggest = $("#search_user").bsSuggest({
            allowNoKeyword: false, //是否允许无关键字时请求数据
            indexId: 0, //data.value 的第几个数据，作为input输入框的内容
            indexKey: 1, //data.value 的第几个数据，作为input输入框的内容
            getDataMethod: "url", //获取数据的方式，总是从 URL 获取
            url: '<?= base_url('admin/puser/search_project_user?pid='.$project['id']) ?>&search=',
            showHeader: false,
            effectiveFields: ["username"],
            processData: function (json) {
                var i, len, data = {
                    value: []
                };

                len = json.length;

                for (i = 0; i < len; i++) {
                    data.value.push({
                        id: json[i].id,
                        username: json[i].username
                    });
                }
                return data;
            }

        },


        ). on('onSetSelectValue', function (e, keyword) {
           // console.log('onSetSelectValue: ', keyword);
           // alert(keyword.key);
        });






        function openProjectUserDialog(op, uid, username, role) {
            initLangsChoiceList(function() {

                $('#userModal').modal('show');

                if (op == 'add')  {
                    $("#user_op").val("add");
                    $('#userModal .modal-title').html("添加团队成员");
                    $("#dv_edit_search_user").hide();
                    $("#dv_search_user").show();

                } else  if (op == 'edit') {
                    $("#user_op").val("edit");
                    $("#project_role").val(role);
                    $("#dv_edit_search_user").show();
                    $("#dv_search_user").hide();
                    $("#edit_search_user").attr("data-id", uid);
                    $("#edit_search_user").val(username);
                    showCheckLang(uid);
                    $('#userModal .modal-title').html("修改团队成员信息");
                }


            });


        }


        function show_history_version(pvid) {
            window.open("<?= base_url('admin/content/history_data?pvid=') ?>" + pvid, '-历史版本', 'fullscreen=1, channelmode= 1,location=0, menubar=no');
        }



        $(document).ready(function () {

            $.get("<?= base_url('admin/version/project_version?pid=') ?>"+pid, function (res) {
                $("#tab-4").html(res);
            })


            
            $('#loading-example-btn').click(function () {
                btn = $(this);
                simpleLoad(btn, true)

                // Ajax example
                //                $.ajax().always(function () {
                //                    simpleLoad($(this), false)
                //                });

                simpleLoad(btn, false)
            });


            // 添加语言
            $("#btn_add_lang").click(function () {
                openLangDialog('add', '');
            });

            $("#btn_add_template").click(function() {

                openTemplateDialog('add', '');

            });


            var icon = "<i class='fa fa-times-circle'></i> ";

            $("#lang_form").validate({
                rules: {
                    lname: {
                        required: true
                    },
                    shorthand : {
                        required: true
                    }
                },

                messages: {
                    lname: icon + "请输入语言名称",
                    shorthand: icon + "请输入语言简写"
                },

                submitHandler: function (form) {


                    var lang_id = $("#dlang_id").val();

                    var submitData = {
                        "pid": pid,
                        'name': $("#lname").val(),
                        'shorthand': $("#shorthand").val(),
                        'remark': $("#remark").val()
                      }

                    if (lang_id == "") {
                        var url =  '<?= base_url("admin/lang/add") ?>';
                    } else {
                        submitData.lang_id = lang_id;
                        var url =  '<?= base_url("admin/lang/update") ?>';
                    }


                    $.post(url,
                        submitData,
                        function (res) {
                            if (res.code == 200) {
                                $('#langModal').modal('hide');
                                getProjectLang();
                                if (lang_id != "") {
                                    toastr.success("修改语言成功", '提示');
                                } else {
                                    toastr.success("添加语言成功", '提示');
                                }

                            } else {
                                toastr.error(res.msg, '提示');
                            }

                        }, "json");
                }
            });



            $("#template_form").validate({
                rules: {
                    tplname: {
                        required: true
                    },
                    tplfolder : {
                        required: true
                    },
                    tplfilename : {
                        required: true
                    },
                    template :  {
                        required: true
                    }


                },

                messages: {
                    tplname: icon + "请输入模板名称",
                    tplfolder: icon + "请输入文件目录规则",
                    tplfilename: icon + "请输入文件名规则",
                    template: icon + "请输入模板",
                },

                submitHandler: function (form) {


                    var tpl_id = $("#tpl_id").val();


                    var folder_config = new Array();

                    var folder_validate = true;

                    $("input[name='folders']").each(function(index,element) {

                        var folder  = $(this).val();
                        var shorthlang = $(this).attr("data-id");

                        if (folder == "") {

                            folder_validate = false;

                        }

                         folder_config.push(
                            {
                                "shorthand": shorthlang,
                                "folder":folder

                            }
                        );
                    });


                    if (!folder_validate) {
                        parent.layer.msg('请检查目录配置,目录配置不能为空!!', {shift: 6});
                        return ;
                    }


                    var submitData = {
                        "pid": pid,
                        'name': $("#tplname").val(),
                        'folder': JSON.stringify(folder_config),
                        'filename': $("#tplfilename").val(),
                        'template': $("#template").val(),
                        'remark': $("#tplremark").val()
                    };


                    if (tpl_id == "") {
                        var url =  '<?= base_url("admin/template/add") ?>';
                    } else {
                        submitData.id = tpl_id;
                        var url =  '<?= base_url("admin/template/update") ?>';
                    }


                    $.post(url,
                        submitData,
                        function (res) {
                            if (res.code == 200) {
                                $('#templateModal').modal('hide');
                                getProjectTemplate();
                                if (tpl_id != "") {
                                    toastr.success("修改模板成功", '提示');
                                } else {
                                    toastr.success("添加模板成功", '提示');
                                }

                            } else {
                                toastr.error(res.msg, '提示');
                            }

                        }, "json");
                }
            });






            $("#project_edit_form").validate({
                rules: {
                    pname: {
                        required: true
                    },
                    remark : {
                        required: true
                    }
                },

                messages: {
                    pname: icon + "请输入项目名称",
                    remark: icon + "请输入项目简介"
                },

                submitHandler: function (form) {
                    var submitData = {
                        "pid": $("#pid").val(),
                        'name': $("#pname").val(),
                        'remark': $("#remark").val()
                    }

                    $.post('<?= base_url("admin/project/update") ?>',
                        submitData,
                        function (res) {
                            if (res.code == 200) {
                                window.location.reload();
                            } else {
                                toastr.error(res.msg, '提示');
                            }
                        }, "json");
                }
            });




            getProjectLang();
            getProjectUser();
            getProjectTemplate();
            showCheckLang('');

            $("#project_role").change(function () {
                showCheckLang('');
            });


            $("#btn_add_user").click(function() {

                var op =  $("#user_op").val();

                if (op == "add") {
                    var user_id = $("#search_user").attr("data-id");
                    if (user_id == undefined) {
                        parent.layer.msg('请选择团队用户', {shift: 6});
                        return;
                    }

                    var url = "<?= base_url("admin/puser/add_project_user") ?>";
                }


                if (op == "edit") {
                    var  user_id = $("#edit_search_user").attr("data-id");

                    var url = "<?= base_url("admin/puser/update_project_user") ?>";
                }



                var lang = new Array();
                $("input[name='ch_lang']:checked").each(function(index,element) {

                    var langid = $(this).val();
                    var permission = $("input[name='permission_"+langid+"']:checked").val();
                    lang.push(
                        {
                            "lang_id": langid,
                            "permission":permission

                        }
                    );
                });


                var lang_permissions = JSON.stringify(lang);
                var role = $("#project_role").val();

                $.post(url,
                        {
                        "user_id": user_id,
                        "project_id": pid,
                        "lang_permissions": lang_permissions,
                        "role": role
                        },

                    function (res) {

                        if (res.code == 200) {
                            $('#userModal').modal('hide');
                            getProjectUser();
                            if (op == 'add') {
                                toastr.success("添加成员成功", '提示');
                            } else if (op == 'edit') {
                                toastr.success("修改成员成功", '提示');
                            }

                        } else {
                            toastr.error(res.msg, '提示');
                        }

                    }, "json");


                /*

                $("").each(function () {
                    var lang = {
                        "name":  $(this).find("[name= 'lname']").val(),
                        "shorthand": $(this).find("[name= 'lshotname']").val(),
                        "remark": $(this).find("[name= 'lremark']").val()
                    };
                    arrayLang.push(lang);
                });*/


            });

        });

        function open_project_dialog(pid) {
            $("#pid").val(pid);
            $('#langModal .modal-title').html("修改语言");
            $.post("<?= base_url("admin/project/get") ?>", {"pid": pid} ,function (res) {
                $("#pname").val(res.name);
                $("#remark").val(res.remark);
                $('#projectModal').modal('show');
            }, "json");

        }

        function open_key(pid) {

            // window.location.href = "<?= base_url('admin/key/keys?pid=') ?>" + pid;
            window.open("<?= base_url('admin/key/keys?pid=') ?>" + pid, 'KEY', 'fullscreen=1, channelmode= 1,location=0, menubar=no');
        }

        function initLangsChoiceList(callback) {
            $.get("<?= base_url('admin/lang/get_lang_choices?pid=') ?>"+pid, function (res) {
                $("#tb_lang_choice").html(res);
                callback();
            });
        }

        function showCheckLang(uid) {
            var role = $("#project_role").val();
            if (role == <?= AppConstants::PROJECT_ROLE_INTERPRETER?>) {

                $("#lang_check_panel").show();

                //是翻译员, 并且是编辑..  获取改翻译员授权的语言信息
                if (uid != '') {
                    $.post("<?= base_url("admin/lang/get_user_permission") ?>", {"uid": uid, "pid": pid} ,function (res) {
                        $("input[name='ch_lang']").each(function(index,element) {
                            var langid = $(this).val();

                            var find = false;
                            for (var i = 0; i<res.length; i ++ ) {
                                if (langid == res[i].lang_id) {
                                    $(this).attr("checked",'checked');
                                    find = true;
                                    $("input[name='permission_"+langid+"'][value="+res[i].permission+"]").get(0).checked = true;
                                    break;
                                }
                            }

                            if (!find) {
                                $(this).get(0).checked = false;
                                $("input[name='permission_"+langid+"'][value=<?= AppConstants::LANG_LANG_PERMISSION_READ_WRITE ?>]").get(0).checked = true;
                            }

                        });

                    }, "json");
                }
            } else {

                $("#lang_check_panel").hide();
            }
        }

        function simpleLoad(btn, state) {
            if (state) {
                btn.children().addClass('fa-spin');
                btn.contents().last().replaceWith(" Loading");
            } else {
                setTimeout(function () {
                    btn.children().removeClass('fa-spin');
                    btn.contents().last().replaceWith(" Refresh");
                }, 2000);
            }
        }


        function getProjectLang() {

            $.get("<?= base_url('admin/lang/lang?pid=') ?>"+pid, function (res) {
                $("#tb_lang").html(res);

            })
        }



        function getProjectTemplate() {

            $.get("<?= base_url('admin/template/templates?pid=') ?>"+pid, function (res) {
                $("#tb_template").html(res);

            })
        }



        function getProjectUser() {
            $.get("<?= base_url('admin/puser/user?pid=') ?>"+pid, function (res) {
                $("#tb_user").html(res);

            })
        }


        function get_template_folder(tpl_id, callback) {
            $.get("<?= base_url('admin/template/folder?tid=') ?>"+tpl_id + "&pid="+ pid, function (res) {
                $("#tb_tpl_folder").html(res);
                callback();

            })
        }


        function deleteLang(lang_id, name) {
            layer.confirm('确认要删除"'+name+'"语言吗？', {
                btn: ['确认','取消'], //按钮
                shade: true, //不显示遮罩,
                shadeClose: true
            }, function(index){

                $.post("<?= base_url("admin/lang/delete") ?>", {"id": lang_id} ,function (res) {
                    layer.close(index);
                    if (res.code == 200) {
                        getProjectLang();
                        toastr.success("删除成功", '提示');
                    } else {
                        toastr.error(res.msg, '提示');
                    }
                }, "json");
            }, function(){

            });
        }


        function deleteTemplate(id, name) {
            layer.confirm('确认要删除"'+name+'"模板吗？', {
                btn: ['确认','取消'], //按钮
                shade: true, //不显示遮罩,
                shadeClose: true
            }, function(index){

                $.post("<?= base_url("admin/template/delete") ?>", {"id": id} ,function (res) {
                    layer.close(index);
                    if (res.code == 200) {
                        getProjectTemplate();
                        toastr.success("删除成功", '提示');
                    } else {
                        toastr.error(res.msg, '提示');
                    }
                }, "json");
            }, function(){

            });
        }





        function deleteUser(uid, username) {
            layer.confirm('确认要删除"'+username+'"用户吗？', {
                btn: ['确认','取消'], //按钮
                shade: true, //不显示遮罩,
                shadeClose: true
            }, function(index){

                $.post("<?= base_url("admin/puser/delete") ?>", {"uid": uid, 'pid': pid} ,function (res) {
                    layer.close(index);
                    if (res.code == 200) {
                        getProjectUser();
                        toastr.success("删除成功", '提示');
                    } else {
                        toastr.error(res.msg, '提示');
                    }
                }, "json");
            }, function(){

            });
        }



        function openLangDialog(op, id) {
            if (op == 'add') {
                $("#dlang_id").val("");
                $("#lname").val("");
                $("#shorthand").val("");
                $("#remark").val("");
                $('#langModal .modal-title').html("添加语言");
                $('#langModal').modal('show');

            } else  if (op == 'edit') {
                $("#dlang_id").val(id);
                $('#langModal .modal-title').html("修改语言");
                $.post("<?= base_url("admin/lang/get") ?>", {"lang_id": id} ,function (res) {
                    $("#lname").val(res.name);
                    $("#shorthand").val(res.shorthand);
                    $("#remark").val(res.remark);

                    $('#langModal').modal('show');

                }, "json");

            }

        }



        function openTemplateDialog(op, id) {
            if (op == 'add') {
                $("#tpl_id").val("");
                $("#tplname").val("");
                $("#tplfolder").val("");
                $("#tplfilename").val("");
                $("#template").val("");
                $("#tplremark").val("");

                $('#templateModal .modal-title').html("添加模板");

                get_template_folder("", function() {
                    $('#templateModal').modal('show');
                });




            } else  if (op == 'edit') {
                $("#tpl_id").val(id);

                $('#templateModal .modal-title').html("修改模板");

                $.post("<?= base_url("admin/template/get") ?>", {"id": id} ,function (res) {
                    $("#tplname").val(res.name);
                    $("#tplfolder").val(res.folder);
                    $("#tplfilename").val(res.filename);
                    $("#template").val(res.template);
                    $("#tplremark").val(res.remark);

                    get_template_folder(id, function() {
                        $('#templateModal').modal('show');
                    });



                }, "json");

            }

        }









    </script>


</body>

</html>
